<?php
class pcapa extends AppBase {
	function _construct(){
		$this->add_resource('html','main.php');
		$this->add_resource('css','app.css');
		$this->add_resource('js','app.js');
		$this->xsession_vars[] = 'pid';
		$this->xsession_vars[] = 'pcap_file';
	}
	function _destruct(){

	}
	function app_load(){
		# Called when app instance is first created
		$this->wappLog($this->class . ' app_load');
	}
	function app_unload(){
		# Called only when the app is being unloaded
		$this->wappLog($this->class . ' app_unload');
		# return true to cancel the unload
		//return true;
	}
	function app_poll($has_focus){
		global $wapi;
		$this->wappLog($this->class . ' app_poll');
		# Called everytime the app is polled
		if ($has_focus){

		}
		echo $this->class . "<br />\n";
		echo $this->title . "<br />\n";
		//echo $this->version . "<br />\n";

	}
	function com_refresh($data){
		global $wapi;
		if ($this->pid == null && $data->file != ''){
			// add security checking to path!!!
			$this->pcap_file = $data->file;
			echo "Processing: " . $this->pcap_file . "<br/>\n";
			$cmd = 'cd ' . $this->path . ';php pcapa.php -f' . $this->pcap_file;
//			$cmd = 'pwd';
			$new_proc = $wapi->proc->run($cmd,-1,'pcapa');
			$this->pid = $new_proc->pid;
		} else {
			echo "Processing: " . $this->pcap_file . "<br/>\n";
			$state = $wapi->proc->get_proc($this->pid,'state');
			$result = $wapi->proc->get_proc($this->pid,'result');
			echo "State: " . $state . "<br/>\n";
			echo "Result: " . '' . "<br/>\n";
			if ($state != 1){
				//$this->pid = null;
				$this->pcap_file = '';
			}
		}
	}
}
?>